# -*- coding: utf-8 -*-

from django.forms.models import ModelForm
from mainapp.models import ClassifferLearningData, UnsupervisedData
from django.forms.forms import Form
from django.forms.fields import ChoiceField, CharField, FileField
from mainapp import get_dm_methods, get_dm_methods_as_choices
from django.forms.widgets import Textarea, TextInput, HiddenInput
from ast import literal_eval
from django.contrib.admin.widgets import AdminFileWidget



class MethodForm(Form):
    
    method = ChoiceField(choices=get_dm_methods_as_choices())


class ClassifferLearningDataForm(ModelForm):
    
    module = CharField(max_length=50, widget=TextInput(attrs={'style':'background-color:#f1f1f1'}))
    
    submited = CharField(widget=HiddenInput(), required=False)
    file = FileField(max_length=100, label=u'Zbiór treningowy', widget=AdminFileWidget())
    
    class Meta:
        
        model = ClassifferLearningData
        
    
class ClassifferTestForm(Form):
    
    test_data = CharField(label=u'Dane do testu', widget=Textarea())
    
    def save(self):
        
        return literal_eval(self.cleaned_data['test_data'])

class UnsupervisedDataForm(ModelForm):
    
    submited = CharField(widget=HiddenInput(), required=False)
    file = FileField(max_length=100, label=u'Zbiór treningowy', widget=AdminFileWidget())
    
    
    class Meta:
        
        model = UnsupervisedData
        
